/**
 * @param {number} x
 * @return {number}
 */

var reverse = function(x) {
  const min = Math.pow(-2, 31);
  const max = Math.pow(2, 31) - 1;
  let multiple = x > 0 ? 1 : -1;
  let num = multiple * Math.abs(x).toString().split('').reverse().join('');
  return (num >= min && num <= max) ? num : 0;
};

console.log(reverse(164881813121));